#include "mainwidget.h"
#include "ui_mainwidget.h"

#include <QDebug>
MainWidget::MainWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::MainWidget)
{
    ui->setupUi(this);

    //    painter = new QPainter(this);
    pixmap = new QPixmap(this->width(),this->height());
    pixmap->fill(QColor(240, 240, 240));
}

void MainWidget::paintEvent(QPaintEvent *event)
{
    qDebug()<<"paint";
    QPainter painter(this);
    QPainter painter1(pixmap);
    //    painter.setPen();

    if(flag==false)
    {
        painter.drawPixmap(0,0,*pixmap);
//        painter.drawLine(startPoint,endPoint);
         painter.drawEllipse((startPoint+endPoint)/2,30,30);

    }
    else
    {
//        painter1.drawLine(startPoint,endPoint);

        painter1.drawEllipse((startPoint+endPoint)/2,30,30);
        painter.drawPixmap(0,0,*pixmap);
    }
}

void MainWidget::mousePressEvent(QMouseEvent *event)
{
    flag=false;
    startPoint= event->pos();
}

void MainWidget::mouseMoveEvent(QMouseEvent *event)
{

    endPoint = event->pos();
    update();
}

void MainWidget::mouseReleaseEvent(QMouseEvent *event)
{
    flag = true;
    update();

}

MainWidget::~MainWidget()
{
    delete ui;
}
